<?php
/**
 * Created by PhpStorm.
 * User: mf
 * Date: 2017/9/4
 * Time: 10:06
 */
namespace app\admin\logic;

use think\Cookie;
use think\Validate;
use tool\Common;

class Base
{
    protected $data = [];
    protected $usrInfo = [];

    public function __construct()
    {
        $this->usrInfo = Cookie::get('userinfo');
    }

    public function init($data = [])
    {
        $this->data = $data;
        return $this;
    }

    //权限ID
    public function getRoleID()
    {
        return $this->usrInfo['roleID'];
    }

    //userID
    public function getUserID()
    {
        return $this->usrInfo['userID'];
    }

    //验证规则
    protected function check($method = '')
    {
        $class = str_replace('logic', 'validate', get_called_class());
        $validateRule = $class::$method();
        $validate = new Validate($validateRule['rule'], $validateRule['msg']);
        if(!$validate->check($this->data)){
            return Common::rm(-1, $validate->getError());
        } else {
            return Common::rm(1, '验证通过');
        }
    }
}
